<?php
/**
 * Description
 *
 * PHP version 7
 *
 * @category Custom
 * @package  Custom
 * @author   ryu <mo5467@126.com>
 * @date     2020-04-29 01:00:21
 * @lastTime 2020-05-01 23:14:22
 * @license  https://opensource.org/licenses/MIT MIT License
 * @link     none
 */
namespace Test\Unit;

use Design\Behavioral\Strategy\Context;
use Design\Behavioral\Strategy\IdComparator;
use Design\Behavioral\Strategy\DateComparator;

class StrategyTest extends \Test\BaseTest
{


    public function provideIntegers()
    {
        return [
            [
                [
                    ['id' => 2],
                    ['id' => 1],
                    ['id' => 3],
                ],
                ['id' => 1],
            ],
            [
                [
                    ['id' => 3],
                    ['id' => 2],
                    ['id' => 1],
                ],
                ['id' => 1],
            ],
        ];

    }//end provideIntegers()


    public function provideDates()
    {
        return [
            [
                [
                    ['date' => '2014-03-03'],
                    ['date' => '2015-03-02'],
                    ['date' => '2013-03-01'],
                ],
                ['date' => '2013-03-01'],
            ],
            [
                [
                    ['date' => '2014-02-03'],
                    ['date' => '2013-02-01'],
                    ['date' => '2015-02-02'],
                ],
                ['date' => '2013-02-01'],
            ],
        ];

    }//end provideDates()


    /**
     * Undocumented function
     *
     * @dataProvider provideIntegers
     * @param        [type] $elements
     * @param        [type] $expect
     * @return       void
     */
    public function testIdComparator($elements, $expect)
    {
        $context = new Context(new IdComparator());

        $el      = $context->executeStrategy($elements);
        $elFirst = array_shift($el);

        $this->assertSame($expect, $elFirst);

    }//end testIdComparator()


    /**
     * Undocumented function
     *
     * @dataProvider provideDates
     * @param        [type] $elements
     * @param        [type] $expect
     * @return       void
     */
    public function testDateComparator($elements, $expect)
    {
        $context = new Context(new DateComparator());

        $el      = $context->executeStrategy($elements);
        $elFirst = array_shift($el);

        $this->assertSame($expect, $elFirst);

    }//end testDateComparator()


}//end class
